<?php
class RoleModel extends Model{
	protected $table='kq_role';
	protected $pk='role_id';
	//表中的字段
	protected $fields=array('role_id','name','pid','status','remark');

	protected $nodeTitles=array();
	protected $rules=array(
			array('name',1,'角色名不能为空','require'),
			array('name',2,'角色名必须在4-16字符内','length','4,16'),
			
		);
	public function readRolePower($role_id){//根据角色id读取其权限，用数组存放，用于权限验证
		$model=new AccessModel();
		$access=$model->getRoleAccess($role_id);

		//print_r($access);
		$a=array();
		for($i=0;$i<count($access);$i++){
			
		$a[$i]=$access[$i]['node_id'];
	 }
		
		
		$modelPower=new PowerModel();
		for($i=0;$i<count($a);$i++){
			$res=$modelPower->getOneRow($a[$i]);
      // print_r($res);
			$nodeTitles[]=$res['title'];
		}
		
       return $nodeTitles; 
	}

	/*
	*获取所有的角色名
	**/
	public function getRole(){
		$sql = "select name from ".$this->table;
		return $this->db->getAll($sql);
	}

	public function getRoleExtAdmin(){
		$sql ="select role_id,name from ".$this->table;
		return $this->db->getAll($sql);
	}

}
?>